home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1995 November / Macworld Nov ’95.toast / Developers / Sample LDEFs 2.0 / Indented LDEF / indent ldef.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-27  |  2.8 KB  |  92 lines  |  [TEXT/KAHL]

  1. // File "indent LDEF.c" - LDEF that lets you indented text within a cell
  2. // This code is placed in the public domain for free use and distribution - MJS
  3. //
  4. //    6/27/95       Changed the Hilite Mode to use accessor functions
  5. //                  Properly save and restore Handle states - MJS
  6. //
  7. //   10/16/93        First released the LDEFs to the net - MJS
  8. //
  9. //    5/23/91       Original snippet which this is shamelessly based on,
  10. //                  by Steven Falkenburg, Apple DTS
  11.  
  12. // * **************************************************************************** * //
  13.  
  14. #include <GestaltEqu.h>
  15. #include <Icons.h>
  16.  
  17. // * **************************************************************************** * //
  18. // * **************************************************************************** * //
  19. // Universal Headers users can replace these with LM accessor functions
  20.  
  21. pascal unsigned char GetHiliteMode(void) = { 0x1EB8, 0x0938 }; /* MOVE.B 0x0938,(A7) */
  22. pascal void SetHiliteMode(unsigned char) = { 0x11DF, 0x0938 }; /* MOVE.B (A7)+,0x0938 */
  23.  
  24. // * **************************************************************************** * //
  25. // * **************************************************************************** * //
  26. // Spacing Constants
  27.  
  28. #define kLeftOffset       2
  29. #define kTopOffset       0
  30.  
  31. // * **************************************************************************** * //
  32.  
  33. pascal void    main(short message, Boolean hilited, Rect *cellRect, Cell theCell,
  34.         short dataOffset, short dataLen, ListHandle theList) {
  35.     short leftDraw,topDraw;
  36.     Ptr cellData;
  37.     ListPtr theListPtr;
  38.     SignedByte hStateList, hStateCells;
  39.     FontInfo fontInfo;
  40.     
  41.     // Lock down the handles
  42.     hStateList = HGetState((Handle) theList);
  43.     HLock((Handle) theList);
  44.     theListPtr = *theList;
  45.     hStateCells = HGetState((Handle) theListPtr->cells);
  46.     HLock((Handle) theListPtr->cells);
  47.     cellData = *(theListPtr->cells);
  48.     
  49.     switch (message) {
  50.       case lInitMsg:
  51.           break;
  52.  
  53.       case lDrawMsg:
  54.         EraseRect(cellRect);
  55.         
  56.           if (dataLen > 0) {
  57.               leftDraw = cellRect->left + theListPtr->indent.h + kLeftOffset;
  58.               topDraw = cellRect->top + theListPtr->indent.v + kTopOffset;
  59.               
  60.               // Determine the indent and add it...
  61.               while (cellData[dataOffset] == '\t') {
  62.                   dataOffset += 1;
  63.                   dataLen -= 1;
  64.                   leftDraw += 12;
  65.                   }
  66.  
  67.             GetFontInfo(&fontInfo);
  68.             MoveTo(leftDraw, topDraw + fontInfo.ascent);
  69.             
  70.             // Condense if the text doesnt fit
  71.             TextFace(0);
  72.             if (TextWidth(cellData, dataOffset, dataLen) > (cellRect->right - leftDraw))
  73.                 TextFace(condense);
  74.  
  75.             DrawText(cellData, dataOffset, dataLen);
  76.               }
  77.  
  78.         if (!hilited) break;
  79.         
  80.       case lHiliteMsg:
  81.           SetHiliteMode(GetHiliteMode() ^ (1L << hiliteBit));
  82.           InvertRect(cellRect);
  83.           break;
  84.  
  85.       case lCloseMsg:
  86.           break;
  87.         }
  88.     
  89.     HSetState((Handle) theListPtr->cells,hStateCells);
  90.     HSetState((Handle) theList, hStateList);
  91.     }
  92.